// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import VueDragResize from 'vue-drag-resize'


import ElementUI from 'element-ui';
import Axios from 'axios';
import VueAxios from 'vue-axios';
import VueCookies from 'vue-cookies'
import 'element-ui/lib/theme-chalk/index.css';
import BaiduMap from 'vue-baidu-map';
import 'jquery'
Vue.config.productionTip = false
Vue.use(ElementUI);
Vue.use(VueDragResize);
Vue.use(VueCookies);
Vue.use(BaiduMap, {
  /* Visit http://lbsyun.baidu.com/apiconsole/key for details about app key. */
  ak: 't6v7gPZ8DT2KzqwtceFZaGYLoCYle52p'
})
import md5 from 'js-md5';
Axios.defaults.baseURL = ''
Axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
Axios.defaults.headers.put['Content-Type'] = 'application/x-www-form-urlencoded';
Axios.interceptors.request.use(
  config => {
    console.log('md5(hello world)',md5('hello world'))
    if (localStorage.JWT_TOKEN) {  // 判断是否存在token，如果存在的话，则每个http header都加上token
      config.headers.Authorization = `${localStorage.JWT_TOKEN}`;
      config.headers.token = `${localStorage.JWT_TOKEN}`;
    }
    return config;
  },
  err => {
    return Promise.reject(err);
  }
)

Axios.interceptors.response.use(response => {
  if (response.data.code === -1){
    ElementUI.Notification({
      title: '提示',
      message: response.data.msg,
      duration: 1000,
      offset: 30
    });
  }
  return response
}, error => {
  return Promise.resolve(error.response)
})
import dateformat from 'dateformat';

Vue.prototype.$dateformat=dateformat;  //其中$xx为新命的名。
Vue.use(VueAxios, Axios);
Vue.prototype.$md5 = md5;
/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>'
})
